<div class="task" onmouseover="show_icons(<%=task_c.id%>)"  onmouseout="hide_icons(<%=task_c.id%>)">
<div class="header">

<%
  task = task_c
  nb = task.subtasks_count
  @flat = nil if not defined?(@flat)
  if(not @flat and nb > 0)
-%>
<div id="collapse_<%=item_name%>_<%=task_c.id%>" style="display:inline;">
  <% if(not expand) -%>
    <%= link_to_remote(image_tag('expand.gif'), {
    :url => {:controller=>'task', :action=>'expand_task',:id=>task_c.id, :item_name=>item_name},
    :update=>"sub_#{item_name}_#{task_c.id}",
    :success=>"expand('#{task_c.id}','#{item_name}');Element.hide('loading')",
    :loading=>"Element.show('loading')"})
    %>
  <% else -%>
    <%= link_to_function(image_tag('collapse.gif'),"collapse('#{task_c.id}','#{item_name}')") %>
  <% end -%>
</div>

<% else -%>
  <div style="padding-left:16px;display:inline"></div>
<% end -%>

<%
  if(task.done==1); donestr = "done"; else; donestr=''; end
  if(task.star==1); starstr = "on"; else; starstr='off'; end
-%>

<!-- Quick done -->
<% if nb == 0 %>
<%= check_box_tag("quickdone_#{task.id}", 1, (task.done==1), {:onclick=>"quick_done(#{task.id});"}) %>
<% else %>
<div style="padding-left:22px;display:inline"></div>
<% end %>

<!-- Star -->
<a href="#" onclick="star_it(<%=task.id%>);return false;"><img src="/images/star_<%=starstr%>_2.gif" id="st<%=task.id%>" title="special"></a>

<!-- State -->
<%= render_state(task) %>

<!-- Prio -->
<%= render(:partial => 'task/priority', :locals => {:p=>task.priority}) %>

<!-- Begun -->
<% if(task.progress==1) -%>
<%= image_tag('inprogress.gif', :title=>'already begun') %>
<% end -%>

</div>


<!-- Title -->

<div class="title">

  <!-- Project -->
  <% if session[:selected_project].to_i != task.project_id and task.project_id != 0 and task.project_id != nil%>
  <b>[<%=task.project.name %>]</b>
  <% end %>

  <% 
  class_str = []
  class_str << "title_done"  if task.done == 1
  class_str << "gtd_project" if not @flat and nb > 0
  -%>
  <span title="<%=task.ancestors_print(' > ')%>" id="title_<%=task.id%>" class="<%=class_str.join(' ')%>">
  <%=h task.title %>
  <% if nb > 0 -%>
  (<%= nb %>)
  <% end -%>
  </span>

  <!-- Resp name -->
  <% if task.user_id != session['user'] and task.state != 'folder' and task.state != 'ref' %>
    <span class="resp"><%=task.user.name %></span>
    <!-- creator -->
    <% if task.created_by!=nil and task.created_by != task.user_id %>
      <i>(from <%=task.creator.name %>)</i>
    <%end%>
  <%end%>

</div>


<%= render(:partial => 'task/deadline', :locals => {:task=>task}) -%>
<% if task.subremains and task.subremains > 0 %>
  <div class="remains" title="total time remaining"><%= task.subremains %></div>
<% end %>

<!-- <div class="tags"><%=task.tags.map{|t| t.name }.join(", ")%></div> -->
<div class="done_on"><% if task.done_on %>done <%= time_ago_in_words(task.done_on) %> ago<% end %></div>

<div class="icons" style="display:none;" id="icons_<%=task_c.id%>">
<a href="#" title="edit" onclick="edit(<%=task.id%>,'<%=item_name%>');return false;"><img id="e_<%=item_name%>_<%=task.id%>" src="/images/edit.gif"></a>
<a href="#" title="cut" onclick="cut(<%=task.id%>,'<%=item_name%>');return false;"><img src="/images/cut.png"></a>
<a href="#" title="paste" onclick="paste(<%=task.id%>,'<%=item_name%>');return false;"><img src="/images/paste.png"></a>
<a href="#" title="notes" onmouseover="mover('n')" onclick="notes(<%=task.id%>);return false;"><img src="/images/notes.png"></a>
<% if(task.notes_count > 0) %><strong><%= task.notes_count%></strong><%end%>
<a href="#" title="print task and subtasks" onmouseover="mover('print')" onclick="print(<%=task.id%>);return false;"><img src="/images/print.png"></a>
<a href="#" title="display only subtasks" onclick="disp_sub(<%=task.id%>,'<%=item_name%>');return false;"><img id="ds<%=task.id%>" src="/images/disp_sub.gif"></a>
<% if task.done==0 -%>
<a href="#" title="add a sub task" onclick="add_sub(<%=task.id%>,'<%=item_name%>');return false;"><img id="a_<%=item_name%>_<%=task.id%>" src="/images/add.png"></a>
<% end -%>
</div>
</div>

<ul id="sub_<%=item_name%>_<%=task.id%>">
<% if expand -%>
<%= render(:partial => 'task/task', :locals => {:item_name=>item_name}, :collection=>task_c.subtasks) -%>
<% end -%>
</ul>


